@include('public.page_styles')
  <link rel="stylesheet" href="{{ asset("/AdminLTE/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css") }}">
<link rel="stylesheet" href="{{ asset("/AdminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.css") }}">
<style>
    .couponStyle{
        padding: 2px 12px;
        background-color: #e4a33a;
    }
    .searchInput{
        width: 292px;
        height: 34px;
        padding: 6px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        background-color: #fff;
        background-image: none;
        border: 1px solid #ccc;
    }
</style>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  @include('public.top')
  <!-- Left side column. contains the logo and sidebar -->
  @include('public.sidebar')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper" id="w_container" >
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
          {{ trans('message.activeUser') }}
        <small>{{ trans('message.list') }}</small>
      </h1>
      <ol class="breadcrumb">
        <li><a ><i class="fa fa-dashboard"></i> {{ trans('message.home') }}</a></li>
        <li><a >{{ trans('message.serviceManage') }}</a></li>
        <li class="active">{{ trans('message.activeUser') }}</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
              <div class="box-header">
                  <div class="pull-right">
                      <div class="form-inline pull-right">
                          <span>
                            <a class="btn btn-sm btn-primary grid-refresh" onclick="refresh()"><i class="fa fa-refresh"></i> {{ trans('message.refresh') }}</a>
                          </span>
                      </div>
                  </div>
                  <form class="form_search" action="{{ url('userAccount/activeManage/list') }}" method="GET" style="margin-bottom:10px">
                      {{--<div style="float:left;margin-right:5px">
                          <label>选择日期</label>
                          <div id="reportrange" class="dateRange">
                              <input  class="searchInput " id="searchDateRange" name="validity" value="{{$validity}}">
                          </div>
                      </div>--}}
                      <div style="float:left;margin-right:5px">
                          <label>下单次数</label>
                          <select class="form-control" name="orderNum">
                              @if($numArr)
                                  @foreach($numArr as $key=>$num)
                                      <option value="{{ $key }}" @if($orderNumS == $key) selected @endif>{{ $num }}</option>
                                  @endforeach
                              @endif
                          </select>
                      </div>
                      <div style="float:left;margin-right:5px">
                          <label>关键字</label>
                          <input type="text" name="phoneSearch"  class="form-control input" placeholder="手机号" value="{{ $phoneS }}">
                      </div>
                      <div class="btn-toolbar" style="padding-top:25px;padding-bottom:0px;margin-bottom:0px">
                          <button type="submit" class="btn btn-primary">检索</button>
                      </div>
                  </form>
              </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                    <th style="width: 50px"><input type="checkbox" id="checkAll" name="checkAll" />全选</th>
                    <th>手机号</th>
                    <th>openID</th>
                    <th>微信昵称</th>
                    <th>下单数</th>
                    <th>注册时间</th>
                    <th>最后下单时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if($activeUsers)
                    @foreach($activeUsers as $key=>$aUser)
                        <tr>
                            <td style="text-align: center;"><input type="checkbox" name="checkItem" value="{{ $aUser['phone'] }}"></td>
                            <td>{{ $aUser['phone'] }}</td>
                            <td>{{ $aUser['open_id'] }}</td>
                            <td>{{ $aUser['nickname'] }}</td>
                            <td>{{ $aUser['order_num'] }}</td>
                            <td>{{ $aUser['register_time'] }}</td>
                            <td>{{ $aUser['order_time'] }}</td>
                            <td >
                                @if(in_array(getOptionId('发送优惠券'),$optionArr))
                                    <a href="{{ url('userAccount/activeManage/send') }}/{{ $aUser['phone'] }}" class="btn btn-warning couponStyle" >发送优惠券</a>　
                                @endif
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
              </table>
                <div>
                    <a class="btn btn-warning couponStyle" id="sendAll" onclick="sendAll()">发送优惠券</a>
                </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
  <!-- /.content-wrapper -->
  @include('public.bottom')

  <!-- Control Sidebar -->
  @include('public.aside')
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
@include('public.javascript')
<script src="{{ asset ("/AdminLTE/bower_components/datatables.net/js/jquery.dataTables.min.js") }}" type="text/javascript"></script>
<script src="{{ asset ("/AdminLTE/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js") }}" type="text/javascript"></script>
<script src="{{ asset ("/AdminLTE/bower_components/jquery-slimscroll/jquery.slimscroll.min.js") }}" type="text/javascript"></script>
{{--<script src="{{ asset ("/AdminLTE/bower_components/fastclick/lib/fastclick.js") }}" type="text/javascript"></script>--}}
<script src="{{ asset ("/js/bootbox.js") }}" type="text/javascript"></script>

<script src="{{ asset ("/AdminLTE/bower_components/moment/min/moment.min.js") }}" type="text/javascript"></script>
<script src="{{ asset ("/AdminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.js") }}" type="text/javascript"></script>
<!-- page script -->
<script>
    $('#reportrange').daterangepicker({
        showDropdowns : true,
        showWeekNumbers : false, //是否显示第几周
        ranges : {
            //'最近1小时': [moment().subtract('hours',1), moment()],
            '今日': [moment().startOf('day'), moment()],
            '昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
            '最近7日': [moment().subtract('days', 6), moment()],
            '最近30日': [moment().subtract('days', 29), moment()]
        },
//            opens : 'right', //日期选择框的弹出位置
        buttonClasses : [ 'btn btn-default' ],
        applyClass : 'btn-small btn-primary blue',
        cancelClass : 'btn-small',
        format : 'YYYY-MM-DD', //控件中from和to 显示的日期格式
//          separator : ' to ',
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                '七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        }
    }, function(start, end, label) {//格式化日期显示框

        $('#reportrange input').val(start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
    });


  $(function(){
      $('#example1').DataTable({
          "language": {
              "url":"{{ asset ("/AdminLTE/bower_components/datatables.net/chinese.json") }}"
          },
          "aaSorting": [[ 4, "desc" ]],//默认第几个排序
          "bStateSave": true,//状态保存
          "aoColumnDefs": [
              //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
              {"orderable":false,"aTargets":[0,1,2,3,7]}// 制定列不参与排序
          ]
      });

      @if(session()->has('success'))
           alertMess("{{session()->get('success')}}");
      @endif


  });
  function sendAll(){
      var ids = '';
      $('input:checkbox[name=checkItem]:checked').each(function(i){
          if(0==i){
              ids = $(this).val();
          }else{
              ids += (","+$(this).val());
          }
      });

//      alert(ids);
//      console.log(ids);

      if(ids.length==0){
          alert('请选择要发送的用户');
          return;
      }

      location.href="{{ url('userAccount/activeManage/send') }}/"+ids;
  }



  $(function(){
      var ids = '';
      function initTableCheckbox() {
          var $thr = $('table thead tr');

          $('#checkAll').click(function(event){
              $tbr.find('input').prop('checked',$(this).prop('checked'));
              if ($(this).prop('checked')) {
                  $tbr.find('input').parent().parent().addClass('warning');
              } else{
                  $tbr.find('input').parent().parent().removeClass('warning');
              }
              /*阻止向上冒泡，以防再次触发点击操作*/
              event.stopPropagation();
          });


          /*点击全选框所在单元格时也触发全选框的点击操作*/
          $('#checkAll').click(function(){
              $(this).find('input').click();
          });

          var $tbr = $('table tbody tr');
          $tbr.find('input').click(function(event){

              $(this).parent().parent().toggleClass('warning');
              $('#checkAll').prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);
              /*阻止向上冒泡，以防再次触发点击操作*/
              event.stopPropagation();

          });
      }
      initTableCheckbox();
  });


</script>
</body>
</html>
